package opdracht10;

public class Temperature {
   private long value;

   private static final long FREEZING_TEMPERATURE = 0L;
   private static final long BOILING_TEMPERATURE = 10000L;
   private static final long LOWEST_TEMPERATURE = -27315L;

   public Temperature(float value) {
      long v = round(value);
      check(v);
      this.value = v;
   }

   public float getValue() {
      return value / 100F;
   }

   public void setValue(float value) {
      long v = round(value);
      check(v);
      this.value = v;
   }

   public boolean isFreezing() {
      return value <= FREEZING_TEMPERATURE;
   }

   public boolean isBoiling() {
      return value >= BOILING_TEMPERATURE;
   }

   public boolean equals(Object o) {
      if (o == null)
         return false;
      if (!(o instanceof Temperature))
         return false;
      return ((Temperature) o).value == this.value;
   }

   public int hashCode() {
      return (int) value;
   }

   private long round(float value) {
      return Math.round(value * 100);
   }

   private void check(long value) {
      if (value < LOWEST_TEMPERATURE) {
         throw new InvalidTemperatureException();
      }
   }
}
